<template>
  <div>
    <el-dialog
      title="题目预览"
      :visible="showRandomDialog"
      @close="closeRandomDialog"
      @open="getDetail"
    >
      <el-row>
        <el-col :span="6"
          >【题型】：{{ questionData.questionType | dealType }}</el-col
        >
        <el-col :span="6">【编号】：{{ questionData.id }}</el-col>
        <el-col :span="6"
          >【难度】：{{ questionData.difficulty | dealDiff }}</el-col
        >
        <el-col :span="6">【标签】：{{ questionData.tags }}</el-col>
        <el-col :span="6">【学科】：{{ questionData.subjectName }}</el-col>
        <el-col :span="6">【目录】：{{ questionData.directoryName }}</el-col>
        <el-col :span="6">【方向】：{{ questionData.direction }}</el-col>
      </el-row>
      <hr />
      【题干】：
      <p v-html="questionData.question" style="color: blue"></p>
      <div v-if="questionData.questionType !== '3'">
        <div>
          {{ questionData.questionType | dealType }} 选项:
          (以下选中的选项为正确答案)
        </div>
        <div v-for="item in questionData.options" :key="item.code">
          <el-radio
            v-if="questionData.questionType === '1'"
            :value="item.isRight"
            :label="1"
            >{{ item.title }}</el-radio
          >
          <el-checkbox
            v-if="questionData.questionType === '2'"
            :value="item.isRight ? true : false"
            >{{ item.title }}</el-checkbox
          >
        </div>
      </div>
      <hr />
      【参考答案】：<el-button type="danger" @click="openAnswerVideo"
        >视频答案预览</el-button
      >
      <div v-show="play" class="video">
        <video ref="video" :src="questionData.videoURL" controls></video>
      </div>
      <hr />
      【答案解析】：
      <p style="display: inline-block" v-html="questionData.answer"></p>
      <hr />
      <p>【题目备注】：{{ questionData.remarks }}</p>
      <template #footer>
        <el-button type="primary" @click="closeRandomDialog">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants'
import { detail } from '@/api/hmmm/questions'
export default {
  name: 'RandomDialog',
  props: {
    question: {
      type: Object,
      default: () => {}
    }
  },
  created () {
    // console.log(this.question);
  },
  data () {
    return {
      showRandomDialog: false,
      questionData: {},
      play: false
    }
  },
  methods: {
    openAnswerVideo () {
      this.play = !this.play
      this.$refs.video.play()
    },
    async getDetail () {
      console.log(this.question.id, 999)
      const { data } = await detail({ id: this.question.id })
      this.questionData = data
      console.log(this.questionData, 666)
    },
    closeRandomDialog () {
      this.showRandomDialog = false
      this.play = false
      this.$refs.video.pause()
    }
  },
  filters: {
    dealType (value) {
      if (value) { return questionType.find((item) => item.value === +value).label + '题' }
    },
    dealDiff (value) {
      if (value) return difficulty.find((item) => item.value === +value).label
    }
  }
}
</script>

<style lang="scss" scoped>
.video {
  width: 390px;
  height: 280px;
  background-color: #8df;
  video {
    width: 100%;
    height: 100%;
  }
}
</style>
